// 医院端添加结算单
<template>
  <div>
    <basic-modal v-if="isView" :modalOpt="modal" :footer="null" @closeModal="closeModal">
      <template>
        <basic-form
          :formInfos="s_FormInfo"
          :formDatas="s_formDatas"
          :rules="s_rules"
          @onSubmit="onSubmit"
          @onChangeType="onChangeType"
          @closeModal="closeModal"
        ></basic-form>
      </template>
    </basic-modal>
  </div>
</template>

<script>
import basicModal from '@/views/app/biz/common/basicModal'
import basicForm from '../common/basicForm'
import {getLicenseByPid} from '@/views/app/biz/regisLicense/regisLicense'
import storage from 'store'
import {
  getInfoByPid,
  saveInfo
} from './settlement'

const s_FormInfo = [
  { label: '结算单号', name: 'settlementNo', type: 'input', placeholder: '请输入结算单号' },
  // { label: '采购单位', name: 'customerName', type: 'input', placeholder: '请输入采购单位' },
  { label: '供应商名称', name: 'supplierOrgPid', type: 'supplier', placeholder: '请选择供应商名称' },
  { label: '结算金额无税总价', name: 'totalIunitprice', type: 'input', placeholder: '请输入结算金额无税总价' },
  { label: '结算金额含税总价', name: 'totalPrice', type: 'input', placeholder: '请输入结算金额含税总价' },
  { label: '税率', name: 'tax', type: 'input', placeholder: '请输入税率' },
  { label: '税额', name: 'taxes', type: 'input', placeholder: '请输入税率' },
  { label: '发票类型', name: 'invoiceType', type: 'dicselect',dicName:'invoiceType', placeholder: '发票类型' },
  { label: '开票信息', name: 'invoiceInfo', type: 'textarea', placeholder: '请输入开票信息' },
  // { label: '发票状态', name: 'invoiceState', type: 'input', placeholder: '请输入发票状态' },
  { label: '采购单位备注', name: 'remarker', type: 'textarea', placeholder: '请输入采购单位备注' },
  { label: ['保存', '重置'], type: 'botton' }
]
const s_formDatas = {
  sysSeq: null,
  pid: null,
  settlementNo: null,
  supplierOrgPid: null,
  supplierName: null,
  totalIunitprice:null,
  totalPrice:null,
  tax:null,
  taxes:null,
  invoiceType: null,
  invoiceInfo: null,
  invoiceState: null,
  settlementState: null,
  remarker: null,
}

const s_rules = {
  invoiceType_: [{ required: true, message: '发票类型必填', trigger: 'blur' }],
  supplierName: [{ required: true, message: '供应商名称必选', trigger: 'blur' }],
  totalIunitprice: [{ required: true, message: '结算金额无税总价必填', trigger: 'change' }],
  totalPrice: [{ required: true, message: '结算金额含税总价必填', trigger: 'change' }],
}
export default {
  components: {
    basicModal,
    basicForm
  },
  data() {
    return {
      loading: false,
      modal: {
        modalVisible: false,
        modalTitle: '新增结算单',
        modalWidth: '1000px',
      },
      isView:false,
      s_FormInfo: s_FormInfo,
      s_formDatas: s_formDatas,
      s_rules: s_rules
    }
  },
  computed: {},
  mounted() {
    
  },
  methods: {
    // 新增按钮 点击了新增
    addModal() {
      this.isView=true
      this.s_FormInfo=[
        { label: '结算单号', name: 'settlementNo', type: 'input', placeholder: '请输入结算单号' },
        { label: '供应商名称', name: 'supplierOrgPid', type: 'supplier', placeholder: '请选择供应商名称' },
        { label: '结算金额无税总价', name: 'totalIunitprice', type: 'input', placeholder: '请输入结算金额无税总价' },
        { label: '结算金额含税总价', name: 'totalPrice', type: 'input', placeholder: '请输入结算金额含税总价' },
        { label: '税率', name: 'tax', type: 'input', placeholder: '请输入税率' },
        { label: '税额', name: 'taxes', type: 'input', placeholder: '请输入税率' },
        { label: '发票类型', name: 'invoiceType', type: 'dicselect',dicName:'invoiceType', placeholder: '发票类型' },
        { label: '开票信息', name: 'invoiceInfo', type: 'textarea', placeholder: '请输入开票信息' },
        // { label: '发票状态', name: 'invoiceState', type: 'input', placeholder: '请输入发票状态' },
        { label: '采购单位备注', name: 'remarker', type: 'textarea', placeholder: '请输入采购单位备注' },
        { label: ['保存', '重置'], type: 'botton' }
      ]
      for (let i in this.s_formDatas) {
        this.s_formDatas[i]=null
      }
      this.s_formDatas = Object.assign( this.s_formDatas,  {
        sysSeq: 0,
        pid: '',
      })
      console.log('点击了新增')
      this.modal.modalVisible = true
      this.modal.modalTitle = "新增结算单"
    },
    // 新增按钮 点击了新增
    editModal(val) {
      this.isView=true
      console.log('点击了编辑')
      this.s_FormInfo=[
        // { label: '结算单号', name: 'settlementNo', type: 'input', placeholder: '请输入结算单号' },
        { label: '供应商名称', name: 'supplierOrgPid', type: 'supplier',isDisabled:true, placeholder: '请选择供应商名称' },
        { label: '结算金额无税总价', name: 'totalIunitprice', type: 'input', placeholder: '请输入结算金额无税总价' },
        { label: '结算金额含税总价', name: 'totalPrice', type: 'input', placeholder: '请输入结算金额含税总价' },
        { label: '税率', name: 'tax', type: 'input', placeholder: '请输入税率' },
        { label: '税额', name: 'taxes', type: 'input', placeholder: '请输入税率' },
        { label: '发票类型', name: 'invoiceType', type: 'dicselect',dicName:'invoiceType',isDisabled:true, placeholder: '发票类型' },
        { label: '开票信息', name: 'invoiceInfo', type: 'textarea', placeholder: '请输入开票信息' },
        // { label: '发票状态', name: 'invoiceState', type: 'input', placeholder: '请输入发票状态' },
        { label: '采购单位备注', name: 'remarker', type: 'textarea', placeholder: '请输入采购单位备注' },
        { label: ['保存', '重置'], type: 'botton' }
      ]
      for (let i in this.s_formDatas) {
        this.s_formDatas[i]=null
      }
      this.getSBypid(val)
      this.modal.modalVisible = true
      this.modal.modalTitle = "修改结算单"
    },
    // 关闭模态详细框
    closeModal() {
      this.modal.modalVisible = false
      this.isView=false
      this.$emit('close')
    },
    // 保存成功关闭模态详细框
    closeModal2() {
      this.modal.modalVisible = false
      this.isView=false
      this.$emit('ok')
    },
    // 模态详细框提交按钮
    onSubmit(val) {
      this.saveObjInfo(val)
    },
    // 保存详细信息
    async saveObjInfo(val) {
      this.loading = true
      // this.$message.loading({ content: '提交中'， })
      let res = await saveInfo(val)
      this.loading = false
      console.log(res)
      if (res && res.code && res.code === 'C1' && res.data) {
        this.$message.success({ content: '提交成功',  duration: 2 })
        this.closeModal2()
      } else {
        this.$message.error({ content: '提交失败',  duration: 2 })
      }
    },
    // 得到初始化信息
    async getSBypid(val) {
      let res = await getInfoByPid(val)
      if (res && res.code && res.code === 'C1') {
        if (res.data) {
          this.s_formDatas = Object.assign( this.s_formDatas, res.data )
        } else {
          this.addModal()
        }
      }
      console.log(res)
    },
    // 表单编号
    onChangeType(name, val) {
      console.log('formName',name)
      console.log('val',val)
      switch (name) {
        case 'zhuCezhPid': 
        // console.log('aaaaaaaaaaaaaa',name)
        const zhucez = this.getZhuCezxx(val)
        break
      }
    },
    // 获取注册证详细信息
    async getZhuCezxx (pid) {
      const res = await getLicenseByPid(pid)
       if (res && res.code && res.code === 'C1' && res.data) {
        this.s_formDatas = Object.assign( this.s_formDatas,  {zhuCezhPid: res.data.pid })
        this.s_formDatas = Object.assign( this.s_formDatas,  {zhuCezh: res.data.zhengZhaohm })
        this.s_formDatas = Object.assign( this.s_formDatas,  {shengChanqymc: res.data.shengChancsmc })
        this.s_formDatas = Object.assign( this.s_formDatas,  {pinMing: res.data.chanPinmc })
       }
    },
    //
    restData (val) {
       this.getSBypid(this.s_formDatas.pid)
    }
  },
}
</script>

<style>
</style>